﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.Shell.Hosting.OpenXmlFileProjectStoreInternals
{
    using System.Diagnostics;
    using System.Xml.Linq;

    internal class ProjectStoreItem : IProjectStoreItem
    {
        private static readonly XNamespace NS = OpenXmlFileProjectStore.NS;

        private readonly OpenXmlFileProjectStore mStore;
        private readonly XElement mItemElement;
        private readonly XAttribute mNameAttribute;
        private readonly XAttribute mItemUriAttribute;

        #region .ctor

        internal ProjectStoreItem(OpenXmlFileProjectStore store, XElement itemElement)
        {

            // Assert parameters
            Debug.Assert(store != null);
            Debug.Assert(itemElement != null);
            Debug.Assert(itemElement.Name == NS + "Item");

            mStore = store;
            mItemElement = itemElement;

            mNameAttribute = itemElement.Attribute("Name");
            Debug.Assert(mNameAttribute != null);

            mItemUriAttribute = itemElement.Attribute("ItemUri");
            Debug.Assert(mItemUriAttribute != null);
        }

        #endregion

        #region IProjectStoreItem Members

        public string Name
        {
            get { return mNameAttribute.Value; }
        }

        #endregion
    }
}
